<script setup>
import * as api from "@/api/v-sys-service/sys-observe/log/index.js";
import Consts from "@/const"
/**
 * 组件挂载后
 */
onMounted(() => {
  init()
})

/**
 * 列表数据
 */
const tableData = ref([])

/**
 * loading状态
 */
const loading = ref({
  tableLoading: false,// 列表loading
})

/**
 * 计算表格属性
 */
const tableInfo = computed(()=>{
  const tableProps = {
    data: tableData.value,
    loading: loading.value.tableLoading,
    rowConfig: { keyField: 'id' },
    checkboxConfig: { highlight: false, reserve: true },
    showSelectCount: true,
    showExportBtn: true,
  }
  return { ...tableProps }
})

/**
 * 分页参数
 */
const pageQuery = reactive({
  page: 1,
  limit: 50,
  total: 0,
  url: '/cloud-sys-service/sys-log/list',
  orders: [
    {column: "createTime", asc: false}
  ],
  filters: [],
  condition: {
    key: "",
  },
})

/**
 * 组件初始化调用函数
 */
const init = () => {
  init_PageQuery()
}

/**
 * 分页查询
 */
const init_PageQuery = async () => {
  loading.value.tableLoading = true
  const { code, data } = await api.list(pageQuery)
  if (code === 200) {
    loading.value.tableLoading = false
    tableData.value = data.records
    pageQuery.total = data.total
  }
}

</script>

<template>
  <div class="log-box flex flex-col">
    <div class="search flex align-center">
      <label class="label">{{'\u2003'}}关键字{{'\u2003'}}</label>
      <el-input
          v-model="pageQuery.condition.key"
          style="width: 180px;" placeholder="请输入关键字"
          @keyup.enter="init_PageQuery" @clear="init_PageQuery" clearable
      />
      <div class="el-button" style="display: none"></div>
      <el-button type="primary" @click="init_PageQuery">
        <template #icon><i-ep-search /></template>搜索
      </el-button>
    </div>
    <v-table
        v-model="pageQuery"
        :table-info="tableInfo"
        :column-info="api.columnInfo"
        @query="init_PageQuery"
    >
      <template #businessType="{row}">
        <el-tag :type="Consts.LOG_BUSINESS_TYPE[row.businessType].type">{{ Consts.LOG_BUSINESS_TYPE[row.businessType].label }}</el-tag>
      </template>
      <template #status="{row}">
        <el-tag :type="Consts.LOG_STATUS_TYPE[row.status].type">{{ Consts.LOG_STATUS_TYPE[row.status].label }}</el-tag>
      </template>
    </v-table>
  </div>
</template>

<style scoped lang="scss">
.log-box {
  padding: 10px;
}
</style>
